{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# sklearn学习案例"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-02-11T10:58:51.498635Z",
     "start_time": "2020-02-11T10:58:50.605800Z"
    }
   },
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import pandas as pd\n",
    "import matplotlib.pyplot as plt\n",
    "import seaborn as sns\n",
    "%matplotlib inline\n",
    "plt.rcParams['font.sans-serif'] = ['SimHei']\n",
    "plt.rcParams['axes.unicode_minus'] = False"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 案例1：工作年限和工资问题"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-02-11T10:58:51.514261Z",
     "start_time": "2020-02-11T10:58:51.498635Z"
    }
   },
   "outputs": [],
   "source": [
    "salary = pd.read_csv(\"./25salary.csv\", index_col=0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-02-11T10:58:51.529888Z",
     "start_time": "2020-02-11T10:58:51.514261Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>year</th>\n",
       "      <th>salary</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <td>1</td>\n",
       "      <td>2.4</td>\n",
       "      <td>6600</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>2</td>\n",
       "      <td>5.5</td>\n",
       "      <td>10100</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>3</td>\n",
       "      <td>3.3</td>\n",
       "      <td>7300</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>4</td>\n",
       "      <td>0.2</td>\n",
       "      <td>5000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>5</td>\n",
       "      <td>1.5</td>\n",
       "      <td>6100</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   year  salary\n",
       "1   2.4    6600\n",
       "2   5.5   10100\n",
       "3   3.3    7300\n",
       "4   0.2    5000\n",
       "5   1.5    6100"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "salary.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-02-11T10:58:51.545514Z",
     "start_time": "2020-02-11T10:58:51.529888Z"
    }
   },
   "outputs": [],
   "source": [
    "# 这里先不用根据工作年限进行排序\n",
    "X = salary[['year']]# X是DataFrame\n",
    "Y = salary['salary'].values# Y是ndarray"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-02-11T10:58:51.714802Z",
     "start_time": "2020-02-11T10:58:51.545514Z"
    }
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYkAAAECCAYAAAALqiumAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjEsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy8QZhcZAAAe9ElEQVR4nO3dfZAkd33f8ff3Zmddt3c83M2tz4h4ZlGiKsdGOsNt5JMjiRNIhiNgbDmA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7+f4PHK0AhmliBVwCL7v4MsATclXN9rjKzPTTq81jOVdnpfcA73f3Xgf8OvD3pA+hi2JDJetrDIPiX8X8E3uPu/UymmKg2a6kX5aJ8N3C/mT0G/LiZ/W7O9Wn6qJkdMbMS8DPA1/KuUOAp4Mbg8TT9TdiZtDuAP/diDS47ANwc/I4/QWPZ50RpMB1gZi8k5nraWTKzx4KEWe7MbA74ANcuKifd/Q9zrBLQdi31+wv2P3PRfseXA38AGPApd1/IuUoAmNkLgEdoNPmWgX/s7k93flc2zOwDwIq7/3HedWkys1uBD9NocjoH/Ky7X070GAX7/yg3wUXmHuBMcKsrIjLyFCRERCSUchIiIhJKQUJEREIpSIiISCgFCRERCaUgISIioQoxX4vIIDOz9wPfcvePm9mvAf8TuBf4QeAb7n6/me0HPkFjCpin3P3twXsfozFFxi3u/to86i/Sie4kRPr3+8AvBI9fS2Ng0zfd/U7gJWZ2C/ASGlOZ3A1MmVlzfrBjwDkFCCkqBQmRPrn7X9GYpvk4jdHeVeBng7uEG4GX0phw8JeBZeAg1+YK+2aRRvCKtFJzk0gyPk5jOon7gKPAE+7+YTN7A7AOvINGc9Np4Is73pfoFAoiSdOdhEgyPkFjcrUv0VgP4YSZnQHeSWOO/88B7wG+EOz/0jwqKRKXpuUQ6ZOZ/RiNSdYedvdTeddHJEkKEiIiEkrNTSIiEkpBQkREQilIiIhIKAUJEREJpSAhIiKh/j9y1ug2dxX2EAAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "# 将数据绘制成散点图\n",
    "plt.scatter(\n",
    "    x=X,\n",
    "    y=Y,\n",
    "    color='black',\n",
    ")\n",
    "plt.xlabel('year')\n",
    "plt.ylabel('salary')\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-02-11T10:58:52.100103Z",
     "start_time": "2020-02-11T10:58:51.714802Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "LinearRegression(copy_X=True, fit_intercept=True, n_jobs=None, normalize=False)"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from sklearn.linear_model import LinearRegression # 单项式线性回归\n",
    "regr = LinearRegression()  # 创建一个线性回归对象\n",
    "regr.fit(X, Y)  # 线性回归拟合数据"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-02-11T10:58:52.120330Z",
     "start_time": "2020-02-11T10:58:52.102139Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Coefficient:[712.59413615]\n",
      "Intercept:5049.009899813835\n"
     ]
    }
   ],
   "source": [
    "print('Coefficient:{}'.format(regr.coef_))  # 系数K\n",
    "print('Intercept:{}'.format(regr.intercept_))  # 截距"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-02-11T10:58:52.301575Z",
     "start_time": "2020-02-11T10:58:52.122364Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Text(0, 0.5, 'salary')"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYkAAAECCAYAAAALqiumAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjEsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy8QZhcZAAAgAElEQVR4nO3de3BkZ3nn8e8zGg2MPFxmNMoEs6hls65iifEAIxybGDIGGzDhkpgAKQQGJ6BC4wqhqC0uJRMCtWLDPcG1niAygB0JiMNmWVggmASMB8fY1nAzl2VxCkng4DCe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XdLzOzbcCniKaAuc3dL41fex3RFBlnufuzy6i/SDNqSYh07mrgZfHjZxMNbPquuz8deJSZnQU8imgqkwuAETOrzw92DnCjAoRUlYKESIfc/d+IpmneSzTaexj4g7iVcDrwaKIJB18NzAI7WJ4r7LtVGsErspa6m0Sy8Umi6SReCewBbnb3j5rZ84BF4E+IupuuAb664nWZTqEgkjW1JESy8SmiydW+RrQewkVmdj3wWqI5/r8EvAX4crz/o8uopEhampZDpENm9ltEk6x9yN0PlF0fkSwpSIiISCJ1N4mISCIFCRERSaQgISIiiRQkREQkkYKEiIgk+v/luiPv3kVh3gAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "# 添加回归线\n",
    "plt.scatter(\n",
    "    x=X,\n",
    "    y=Y,\n",
    "    color='black'\n",
    ")\n",
    "plt.plot(\n",
    "    X,\n",
    "    regr.predict(X),# 预测Y值\n",
    "    linewidth=3,\n",
    "    color='blue',\n",
    ")\n",
    "plt.xlabel('year')\n",
    "plt.ylabel('salary')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "单项式回归分析画出的回归线与散点不完全契合，散点图显示为随着工作年限增加，薪资增长速度放缓，而画出的回归线是等速增长。"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-02-11T09:45:21.397597Z",
     "start_time": "2020-02-11T09:45:21.389590Z"
    }
   },
   "source": [
    "使用多项式线性回归"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-02-11T10:58:52.321728Z",
     "start_time": "2020-02-11T10:58:52.303620Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "LinearRegression(copy_X=True, fit_intercept=True, n_jobs=None, normalize=False)"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from sklearn.preprocessing import PolynomialFeatures # 多项式特征\n",
    "poly_reg=PolynomialFeatures(degree=2)# 二次项\n",
    "X_=poly_reg.fit_transform(X)\n",
    "regr=LinearRegression()\n",
    "regr.fit(X_,Y)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-02-11T10:58:52.341867Z",
     "start_time": "2020-02-11T10:58:52.323755Z"
    }
   },
   "outputs": [],
   "source": [
    "X2=X.sort_values(['year'])# 根据工作年限升序排序\n",
    "X2_=poly_reg.fit_transform(X2)# 将X2从DataFrame转为ndarray，可以使用？X2（或者type(X2)）进行查看"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-02-11T10:58:52.523509Z",
     "start_time": "2020-02-11T10:58:52.343888Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[<matplotlib.lines.Line2D at 0x2193d6c5088>]"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAX0AAAD2CAYAAAA6eVf+AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjEsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy8QZhcZAAAgAElEQVR4nO3deZxcVZn/8c/TW5KmDUk6ISGErgjDjKAYgWaLgGGRTTaj49YjikJrgjosymLDC8VpcEGQcQhjM0HQbhkZRtmMLKJI9AdKIovIzAgzpFvCkpCEQGjM0v38/rhVqe5Obbf61v59v173Rd1Tt+49VR2eOvWcc88xd0dERGpDXakrICIixaOgLyJSQxT0RURqiIK+iEgNUdAXEakhDaWuQCbTp0/3uXPnlroaIiIVZeXKla+4+4xUz5V10J87dy4rVqwodTVERCqKmfWne07pHR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SrHOoHqFVbN1auqc/oiIjJatbf0RURkBAV9KVvlvhazSCWq2qBfjPV482FmM81seanrkWBmO5vZz83sPjP7qZk1lbpOkHot5hJXaZT43/GxUtcjwcwazGzAzB6Mb/uWuk4jmdkSMzu51PVIMLNFIz6rx83se6WuEwT/7s1smZmtKFSdqjLoF2s93rDigexmglXEykUHcLW7Hwu8BBxf4vokjF2Lef8S12esq0guClQO3gnc4u4L4tsfS12hBDM7HJjl7neVui4J7n594rMimPL9hhJXKeHjQF98jP5bzCzysfpVGfSBBey4Hm85GCJYZvK1Ulckwd2XuPv98d0ZwJpS1ifB3X/t7o+MWIv54VLXKcHMjgLeIPiSLBeHACeZ2e/jv3IjmUF3vMyskSCgrjKzU0tdn7HMbDdgpruXy8Id64B3mNkUYHfgL1FfoFqDfk7r8Rabu79WrusImNmhwFR3f6TUdUkYsxbz1hJXB4B4+utS4KJS12WMR4Fj3P0goBE4scT1STgdeBr4JnCQmX2+xPUZ62zg+lJXYoTfADHgC8B/EcSvSFVr0C/KerzVwsymAd8FPlXquow0Zi3mU0pdn7iLgCXu/mqpKzLGk+7+YvzxCqAsUprAfkCPu78E9AJHlrg+25lZHUF9HixxVUa6DPisu18O/DdwRtQXqNZgWJT1eKtBvOX6H8DF7j6eye0ilWIt5nIJsscAZ5vZg8C7zOzfSlyfhB+a2TwzqwdOA54odYXingX2iD9uZ3wTKEbtcOB3Xl43K00F9o3/HQ8mWGY2UlV5c5aZTSbkerzFZGYPxjuQSs7MFgFXkAwS17v7j0tYJSDlWsxnl9n/nOX2d3wH8CPAgDvdvavEVQLAzN4C3EiQYm0EPujuqzO/qjjM7Apghbv/pNR1STCzg4DvE6R4Hgbe7+6bIr1Gmf1/FJl40Hgv8FD8p6WISM2r2qAvIiI7qtacvoiIpKCgLyJSQxT0RURqiIK+iEgNUdAXEakh/x9zdCd1y1xzjgAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.scatter(\n",
    "    X,\n",
    "    Y,\n",
    "    color='black'\n",
    ")\n",
    "plt.plot(\n",
    "    X2,\n",
    "    regr.predict(X2_),\n",
    "    color='blue',\n",
    "    linewidth=3,\n",
    ")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 案例2：Fisher的鸢尾花数据（适用于分类问题）\n",
    "著名的统计学家Fisher在研究判别分析问题时收集了关于鸢尾花的一些数据，这是个非常经典的数据集，datasets中自然也带有这个数据集；这个数据集包含了150个鸢尾花样本，对应3种鸢尾花，各50个样本（target），以及它们各自对应的4种关于花外形的数据（自变量）；这里我们使用load_iris(return_X_y)来导出数据："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-02-11T11:00:31.072477Z",
     "start_time": "2020-02-11T11:00:31.056849Z"
    }
   },
   "outputs": [],
   "source": [
    "from sklearn.datasets import load_iris\n",
    "iris=load_iris()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-02-11T11:19:24.599560Z",
     "start_time": "2020-02-11T11:19:24.583935Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(150, 4)"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "iris.data.shape# 150条数据，4个维度"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-02-11T11:26:30.951028Z",
     "start_time": "2020-02-11T11:26:30.948023Z"
    },
    "collapsed": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      ".. _iris_dataset:\n",
      "\n",
      "Iris plants dataset\n",
      "--------------------\n",
      "\n",
      "**Data Set Characteristics:**\n",
      "\n",
      "    :Number of Instances: 150 (50 in each of three classes)\n",
      "    :Number of Attributes: 4 numeric, predictive attributes and the class\n",
      "    :Attribute Information:\n",
      "        - sepal length in cm\n",
      "        - sepal width in cm\n",
      "        - petal length in cm\n",
      "        - petal width in cm\n",
      "        - class:\n",
      "                - Iris-Setosa\n",
      "                - Iris-Versicolour\n",
      "                - Iris-Virginica\n",
      "                \n",
      "    :Summary Statistics:\n",
      "\n",
      "    ============== ==== ==== ======= ===== ====================\n",
      "                    Min  Max   Mean    SD   Class Correlation\n",
      "    ============== ==== ==== ======= ===== ====================\n",
      "    sepal length:   4.3  7.9   5.84   0.83    0.7826\n",
      "    sepal width:    2.0  4.4   3.05   0.43   -0.4194\n",
      "    petal length:   1.0  6.9   3.76   1.76    0.9490  (high!)\n",
      "    petal width:    0.1  2.5   1.20   0.76    0.9565  (high!)\n",
      "    ============== ==== ==== ======= ===== ====================\n",
      "\n",
      "    :Missing Attribute Values: None\n",
      "    :Class Distribution: 33.3% for each of 3 classes.\n",
      "    :Creator: R.A. Fisher\n",
      "    :Donor: Michael Marshall (MARSHALL%PLU@io.arc.nasa.gov)\n",
      "    :Date: July, 1988\n",
      "\n",
      "The famous Iris database, first used by Sir R.A. Fisher. The dataset is taken\n",
      "from Fisher's paper. Note that it's the same as in R, but not as in the UCI\n",
      "Machine Learning Repository, which has two wrong data points.\n",
      "\n",
      "This is perhaps the best known database to be found in the\n",
      "pattern recognition literature.  Fisher's paper is a classic in the field and\n",
      "is referenced frequently to this day.  (See Duda & Hart, for example.)  The\n",
      "data set contains 3 classes of 50 instances each, where each class refers to a\n",
      "type of iris plant.  One class is linearly separable from the other 2; the\n",
      "latter are NOT linearly separable from each other.\n",
      "\n",
      ".. topic:: References\n",
      "\n",
      "   - Fisher, R.A. \"The use of multiple measurements in taxonomic problems\"\n",
      "     Annual Eugenics, 7, Part II, 179-188 (1936); also in \"Contributions to\n",
      "     Mathematical Statistics\" (John Wiley, NY, 1950).\n",
      "   - Duda, R.O., & Hart, P.E. (1973) Pattern Classification and Scene Analysis.\n",
      "     (Q327.D83) John Wiley & Sons.  ISBN 0-471-22361-1.  See page 218.\n",
      "   - Dasarathy, B.V. (1980) \"Nosing Around the Neighborhood: A New System\n",
      "     Structure and Classification Rule for Recognition in Partially Exposed\n",
      "     Environments\".  IEEE Transactions on Pattern Analysis and Machine\n",
      "     Intelligence, Vol. PAMI-2, No. 1, 67-71.\n",
      "   - Gates, G.W. (1972) \"The Reduced Nearest Neighbor Rule\".  IEEE Transactions\n",
      "     on Information Theory, May 1972, 431-433.\n",
      "   - See also: 1988 MLC Proceedings, 54-64.  Cheeseman et al\"s AUTOCLASS II\n",
      "     conceptual clustering system finds 3 classes in the data.\n",
      "   - Many, many more ...\n"
     ]
    }
   ],
   "source": [
    "# 查看数据说明\n",
    "print(iris.DESCR)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-02-11T11:26:15.351007Z",
     "start_time": "2020-02-11T11:26:15.347003Z"
    }
   },
   "outputs": [],
   "source": [
    "from sklearn.model_selection import train_test_split\n",
    "# 选择25%的数据作为测试集\n",
    "X_train,X_test,Y_train,Y_test=train_test_split(iris.data,iris.target,test_size=0.25,random_state=33)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-02-11T11:29:49.818145Z",
     "start_time": "2020-02-11T11:29:49.802528Z"
    }
   },
   "outputs": [],
   "source": [
    "from sklearn.preprocessing import StandardScaler# 数据标准化模块\n",
    "from sklearn.neighbors import KNeighborsClassifier# K近邻分类器\n",
    "\n",
    "# 对训练和测试的特征数据进行标准化\n",
    "ss=StandardScaler()\n",
    "X_train=ss.fit_transform(X_train)\n",
    "X_test=ss.transform(X_test)\n",
    "\n",
    "# 使用K近邻分类器对测试数据进行类别预测，预测结果存储在变量y_predict中\n",
    "knc=KNeighborsClassifier()\n",
    "knc.fit(X_train,Y_train)\n",
    "y_predict = knc.predict(X_test)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-02-11T11:30:57.410909Z",
     "start_time": "2020-02-11T11:30:57.379675Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The accuracy of K-Nearest Neighbor Classifier is 0.8947368421052632\n"
     ]
    }
   ],
   "source": [
    "# 使用模型自带的评估函数进行准确性测评\n",
    "print('The accuracy of K-Nearest Neighbor Classifier is {}'.format(knc.score(X_test,Y_test)))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-02-11T11:36:49.105310Z",
     "start_time": "2020-02-11T11:36:49.089684Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "              precision    recall  f1-score   support\n",
      "\n",
      "      setosa       1.00      1.00      1.00         8\n",
      "  versicolor       0.73      1.00      0.85        11\n",
      "   virginica       1.00      0.79      0.88        19\n",
      "\n",
      "    accuracy                           0.89        38\n",
      "   macro avg       0.91      0.93      0.91        38\n",
      "weighted avg       0.92      0.89      0.90        38\n",
      "\n"
     ]
    }
   ],
   "source": [
    "# 使用sklearn.metrics里面的classification_report模块对预测结果做更加详细的分析\n",
    "from sklearn.metrics import classification_report\n",
    "print(classification_report(Y_test,y_predict,target_names=iris.target_names))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 案例3：波士顿房价数据（适用于回归任务）\n",
    "这个数据集包含了506处波士顿不同地理位置的房产的房价数据（因变量），和与之对应的包含房屋以及房屋周围的详细信息（自变量），其中包含城镇犯罪率、一氧化氮浓度、住宅平均房间数、到中心区域的加权距离以及自住房平均房价等13个维度的数据，因此，波士顿房价数据集能够应用到回归问题上，这里使用load_boston(return_X_y=False)方法来导出数据，其中参数return_X_y控制输出数据的结构，若选为True，则将因变量和自变量独立导出"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-02-11T11:40:09.214879Z",
     "start_time": "2020-02-11T11:40:09.204870Z"
    }
   },
   "outputs": [],
   "source": [
    "from sklearn.datasets import load_boston\n",
    "house = load_boston()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3.7.4 64-bit ('base': conda)",
   "language": "python",
   "name": "python37464bitbaseconda74613b0a79204effa10b1ef2bb70dd48"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.4"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": false,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": true
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
